 /* Created by Timothy Cheung
|---------------------------------------------------------------------------------------------------
| XTemplate for Details View Availability Tab Content (@author : Timothy Cheung)
|---------------------------------------------------------------------------------------------------
| This DataView contains the skeleton code for the HTML content for the Availability tab
| of Details View. Variables are loaded when the attached store 'DetailsAvails' accesses 
| availability.php, which loads the availability object parsed from the X-services API generated XML
| Variables:
| { location }  -   Call number of loaded title
| { docnum }    -   Accesses the document number required for the generating of the Reserve button, 
|                   returns both the generated url as well as required HTML tags
| { locator }   -   Generates the code required for the Locator button
| { html }      -   Contains the availability entries returned from availability.php, laced with required
|                   HTML tags. Information includes Barcode, Item status, Library, Collection, Due Date 
|                   and Due Time, as well as the number of items displayed against total number of entries
|                   which passed the filters. Generates a button link to library catalogue if the item has 
|                   multiple entries, to allow users to view further records
*/  

Ext.define("MajorProjectSenchaTouch.view.DetailsViewModule.AvailTabDataView", {
    extend:"Ext.DataView",
    xtype: "availtabdataview",
    requires:[
    ],
    config:{        
      
        itemTpl: new Ext.XTemplate('<tpl for=".">',
                                    '<div id="overBlockBtm">',
                                    '<div id="avaTopBlock">', //top block
                                        '<div class="mtCall"><h2>{ location }</h2></div>',
                                     '</div>', //close top
                                     '<div id="avaMidBlock">', //mid img block
                                        '<div class="mb">',
                                                '<div id="buttons">',
                                                '<div id="b1">{ docnum }</div>',
                                                  '<div id="b2">{ locator }</div>',
                                        '</div>', //close class mb
                                      '</div>', //close img block
                                      
                                       '<div id="htmlpad">{ html }</div>',
                                       
                                       '</div>',//close overBlock
                                    '</tpl>'
            ),
            store: 'DetailsAvails',
            listeners:{
                itemtap:function(dv,index,target, record, e){
                    var target = e.target;
                    if(target.name == "locateBtn"){
                        var collection = record.data.collection;
                        var shelfnumber = record.data.location;
                        var fpControl = MajorProjectSenchaTouch.app.getController('ShelfLocator');
                        fpControl.processLocationData(collection, shelfnumber);
                    }
                    if(target.name == "eachlocateBtn"){
                        var collectionShelfnumber = target.value;
                        console.log(collectionShelfnumber);
                        // splits the collection and shelfnumber data with '_' as a delimiter
                        var collectionAndShelfnumberArray = collectionShelfnumber.split('_');
                        var collection = collectionAndShelfnumberArray[0];
                        var shelfnumber = collectionAndShelfnumberArray[1];
                        var fpControl = MajorProjectSenchaTouch.app.getController('ShelfLocator');
                        fpControl.processLocationData(collection, shelfnumber);
                    }
                }
            }
    }
});

